package com.google.android.exoplayer2.upstream;

import android.content.Context;
import android.content.res.AssetManager;
import android.net.Uri;
import androidx.annotation.Nullable;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import o.alf;

public final class AssetDataSource extends alf {
    private static int ʽ = 0;
    private static int ॱॱ = 1;
    private final AssetManager ˊ;
    private boolean ˋ;
    @Nullable
    private Uri ˎ;
    @Nullable
    private InputStream ˏ;
    private long ॱ;

    public static final class AssetDataSourceException extends IOException {
        public AssetDataSourceException(IOException iOException) {
            super(iOException);
        }
    }

    public AssetDataSource(Context context) {
        super(false);
        this.ˊ = context.getAssets();
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public long ˋ(com.google.android.exoplayer2.upstream.DataSpec r13) throws com.google.android.exoplayer2.upstream.AssetDataSource.AssetDataSourceException {
        /*
        r12 = this;
        r10 = -1;
        r4 = 5;
        r1 = 0;
        r2 = 1;
        r0 = r13.ˎ;	 Catch:{ IOException -> 0x00c7 }
        r12.ˎ = r0;	 Catch:{ IOException -> 0x00c7 }
        r0 = r12.ˎ;	 Catch:{ IOException -> 0x00c7 }
        r3 = r0.getPath();	 Catch:{ IOException -> 0x00c7 }
        r0 = "/android_asset/";
        r5 = ॱॱ;
        r5 = r5 + 59;
        r6 = r5 % 128;
        ʽ = r6;
        r5 = r5 % 2;
        if (r5 == 0) goto L_0x001d;
    L_0x001d:
        r5 = 1;
        r5 = new java.lang.Object[r5];	 Catch:{ all -> 0x017c }
        r6 = 0;
        r5[r6] = r0;	 Catch:{ all -> 0x017c }
        r0 = java.lang.String.class;
        r6 = "startsWith";
        r7 = 1;
        r7 = new java.lang.Class[r7];	 Catch:{ all -> 0x017c }
        r8 = 0;
        r9 = java.lang.String.class;
        r7[r8] = r9;	 Catch:{ all -> 0x017c }
        r0 = r0.getMethod(r6, r7);	 Catch:{ all -> 0x017c }
        r0 = r0.invoke(r3, r5);	 Catch:{ all -> 0x017c }
        r0 = (java.lang.Boolean) r0;	 Catch:{ all -> 0x017c }
        r0 = r0.booleanValue();	 Catch:{ all -> 0x017c }
        if (r0 == 0) goto L_0x0155;
    L_0x003f:
        r0 = 64;
    L_0x0041:
        switch(r0) {
            case 64: goto L_0x0158;
            default: goto L_0x0044;
        };
    L_0x0044:
        r4 = "/";
        r0 = ʽ;
        r0 = r0 + 39;
        r5 = r0 % 128;
        ॱॱ = r5;
        r0 = r0 % 2;
        if (r0 != 0) goto L_0x0198;
    L_0x0052:
        r0 = 50;
    L_0x0054:
        switch(r0) {
            case 50: goto L_0x0057;
            default: goto L_0x0057;
        };
    L_0x0057:
        r0 = 1;
        r0 = new java.lang.Object[r0];	 Catch:{ all -> 0x014d }
        r5 = 0;
        r0[r5] = r4;	 Catch:{ all -> 0x014d }
        r4 = java.lang.String.class;
        r5 = "startsWith";
        r6 = 1;
        r6 = new java.lang.Class[r6];	 Catch:{ all -> 0x014d }
        r7 = 0;
        r8 = java.lang.String.class;
        r6[r7] = r8;	 Catch:{ all -> 0x014d }
        r4 = r4.getMethod(r5, r6);	 Catch:{ all -> 0x014d }
        r0 = r4.invoke(r3, r0);	 Catch:{ all -> 0x014d }
        r0 = (java.lang.Boolean) r0;	 Catch:{ all -> 0x014d }
        r0 = r0.booleanValue();	 Catch:{ all -> 0x014d }
        if (r0 == 0) goto L_0x019d;
    L_0x0079:
        r0 = 54;
    L_0x007b:
        switch(r0) {
            case 54: goto L_0x00ce;
            default: goto L_0x007e;
        };
    L_0x007e:
        r0 = r3;
    L_0x007f:
        r12.ˊ(r13);	 Catch:{ IOException -> 0x00c7 }
        r3 = r12.ˊ;	 Catch:{ IOException -> 0x00c7 }
        r4 = 2;
        r4 = new java.lang.Object[r4];	 Catch:{ all -> 0x0186 }
        r5 = 1;
        r4[r5] = r0;	 Catch:{ all -> 0x0186 }
        r0 = 0;
        r4[r0] = r3;	 Catch:{ all -> 0x0186 }
        r0 = 5;
        r3 = 0;
        r5 = 15235; // 0x3b83 float:2.1349E-41 double:7.527E-320;
        r0 = o.avb.ˏ(r0, r3, r5);	 Catch:{ all -> 0x0186 }
        r0 = (java.lang.Class) r0;	 Catch:{ all -> 0x0186 }
        r3 = "ˏ";
        r5 = 2;
        r5 = new java.lang.Class[r5];	 Catch:{ all -> 0x0186 }
        r6 = 0;
        r7 = android.content.res.AssetManager.class;
        r5[r6] = r7;	 Catch:{ all -> 0x0186 }
        r6 = 1;
        r7 = java.lang.String.class;
        r5[r6] = r7;	 Catch:{ all -> 0x0186 }
        r0 = r0.getMethod(r3, r5);	 Catch:{ all -> 0x0186 }
        r3 = 0;
        r0 = r0.invoke(r3, r4);	 Catch:{ all -> 0x0186 }
        r0 = (java.io.InputStream) r0;	 Catch:{ all -> 0x0186 }
        r12.ˏ = r0;	 Catch:{ IOException -> 0x00c7 }
        r0 = r12.ˏ;	 Catch:{ IOException -> 0x00c7 }
        r4 = r13.ॱॱ;	 Catch:{ IOException -> 0x00c7 }
        r4 = r0.skip(r4);	 Catch:{ IOException -> 0x00c7 }
        r6 = r13.ॱॱ;	 Catch:{ IOException -> 0x00c7 }
        r0 = (r4 > r6 ? 1 : (r4 == r6 ? 0 : -1));
        if (r0 >= 0) goto L_0x0145;
    L_0x00c1:
        r0 = new java.io.EOFException;	 Catch:{ IOException -> 0x00c7 }
        r0.<init>();	 Catch:{ IOException -> 0x00c7 }
        throw r0;	 Catch:{ IOException -> 0x00c7 }
    L_0x00c7:
        r0 = move-exception;
        r1 = new com.google.android.exoplayer2.upstream.AssetDataSource$AssetDataSourceException;
        r1.<init>(r0);
        throw r1;
    L_0x00ce:
        r0 = 1;
        r4 = 1;
        r4 = new java.lang.Object[r4];	 Catch:{ all -> 0x018f }
        r0 = java.lang.Integer.valueOf(r0);	 Catch:{ all -> 0x018f }
        r5 = 0;
        r4[r5] = r0;	 Catch:{ all -> 0x018f }
        r0 = java.lang.String.class;
        r5 = "substring";
        r6 = 1;
        r6 = new java.lang.Class[r6];	 Catch:{ all -> 0x018f }
        r7 = 0;
        r8 = java.lang.Integer.TYPE;	 Catch:{ all -> 0x018f }
        r6[r7] = r8;	 Catch:{ all -> 0x018f }
        r0 = r0.getMethod(r5, r6);	 Catch:{ all -> 0x018f }
        r0 = r0.invoke(r3, r4);	 Catch:{ all -> 0x018f }
        r0 = (java.lang.String) r0;	 Catch:{ all -> 0x018f }
        r3 = ʽ;	 Catch:{ Exception -> 0x013b }
        r3 = r3 + 75;
        r4 = r3 % 128;
        ॱॱ = r4;	 Catch:{ Exception -> 0x0184 }
        r3 = r3 % 2;
        if (r3 != 0) goto L_0x007f;
    L_0x00fb:
        goto L_0x007f;
    L_0x00fc:
        r0 = ॱॱ;
        r0 = r0 + 33;
        r1 = r0 % 128;
        ʽ = r1;
        r0 = r0 % 2;
        if (r0 == 0) goto L_0x0108;
    L_0x0108:
        r0 = r13.ᐝ;	 Catch:{ IOException -> 0x00c7 }
        r12.ॱ = r0;	 Catch:{ IOException -> 0x00c7 }
    L_0x010c:
        r12.ˋ = r2;
        r12.ˎ(r13);
        r0 = r12.ॱ;
        return r0;
    L_0x0114:
        r0 = r2;
    L_0x0115:
        switch(r0) {
            case 0: goto L_0x00fc;
            default: goto L_0x0118;
        };
    L_0x0118:
        r0 = r12.ˏ;	 Catch:{ IOException -> 0x00c7 }
        r0 = r0.available();	 Catch:{ IOException -> 0x00c7 }
        r0 = (long) r0;	 Catch:{ IOException -> 0x00c7 }
        r12.ॱ = r0;	 Catch:{ IOException -> 0x00c7 }
        r0 = r12.ॱ;	 Catch:{ IOException -> 0x00c7 }
        r4 = 2147483647; // 0x7fffffff float:NaN double:1.060997895E-314;
        r0 = (r0 > r4 ? 1 : (r0 == r4 ? 0 : -1));
        if (r0 != 0) goto L_0x010c;
    L_0x012a:
        r0 = -1;
        r12.ॱ = r0;	 Catch:{ IOException -> 0x00c7 }
        r0 = ʽ;
        r0 = r0 + 41;
        r1 = r0 % 128;
        ॱॱ = r1;
        r0 = r0 % 2;
        if (r0 != 0) goto L_0x010c;
    L_0x013a:
        goto L_0x010c;
    L_0x013b:
        r0 = move-exception;
        throw r0;
    L_0x013d:
        r0 = move-exception;
        r1 = r0.getCause();	 Catch:{ IOException -> 0x00c7 }
        if (r1 == 0) goto L_0x019c;
    L_0x0144:
        throw r1;	 Catch:{ IOException -> 0x00c7 }
    L_0x0145:
        r4 = r13.ᐝ;	 Catch:{ IOException -> 0x00c7 }
        r0 = (r4 > r10 ? 1 : (r4 == r10 ? 0 : -1));
        if (r0 == 0) goto L_0x0114;
    L_0x014b:
        r0 = r1;
        goto L_0x0115;
    L_0x014d:
        r0 = move-exception;
        r1 = r0.getCause();	 Catch:{ IOException -> 0x00c7 }
        if (r1 == 0) goto L_0x0197;
    L_0x0154:
        throw r1;	 Catch:{ IOException -> 0x00c7 }
    L_0x0155:
        r0 = r4;
        goto L_0x0041;
    L_0x0158:
        r0 = 15;
        r4 = 1;
        r4 = new java.lang.Object[r4];	 Catch:{ all -> 0x013d }
        r0 = java.lang.Integer.valueOf(r0);	 Catch:{ all -> 0x013d }
        r5 = 0;
        r4[r5] = r0;	 Catch:{ all -> 0x013d }
        r0 = java.lang.String.class;
        r5 = "substring";
        r6 = 1;
        r6 = new java.lang.Class[r6];	 Catch:{ all -> 0x013d }
        r7 = 0;
        r8 = java.lang.Integer.TYPE;	 Catch:{ all -> 0x013d }
        r6[r7] = r8;	 Catch:{ all -> 0x013d }
        r0 = r0.getMethod(r5, r6);	 Catch:{ all -> 0x013d }
        r0 = r0.invoke(r3, r4);	 Catch:{ all -> 0x013d }
        r0 = (java.lang.String) r0;	 Catch:{ all -> 0x013d }
        goto L_0x007f;
    L_0x017c:
        r0 = move-exception;
        r1 = r0.getCause();	 Catch:{ IOException -> 0x00c7 }
        if (r1 == 0) goto L_0x01a1;
    L_0x0183:
        throw r1;	 Catch:{ IOException -> 0x00c7 }
    L_0x0184:
        r0 = move-exception;
        throw r0;
    L_0x0186:
        r0 = move-exception;
        r1 = r0.getCause();	 Catch:{ IOException -> 0x00c7 }
        if (r1 == 0) goto L_0x018e;
    L_0x018d:
        throw r1;	 Catch:{ IOException -> 0x00c7 }
    L_0x018e:
        throw r0;	 Catch:{ IOException -> 0x00c7 }
    L_0x018f:
        r0 = move-exception;
        r1 = r0.getCause();	 Catch:{ IOException -> 0x00c7 }
        if (r1 == 0) goto L_0x01a2;
    L_0x0196:
        throw r1;	 Catch:{ IOException -> 0x00c7 }
    L_0x0197:
        throw r0;	 Catch:{ IOException -> 0x00c7 }
    L_0x0198:
        r0 = 93;
        goto L_0x0054;
    L_0x019c:
        throw r0;	 Catch:{ IOException -> 0x00c7 }
    L_0x019d:
        r0 = 57;
        goto L_0x007b;
    L_0x01a1:
        throw r0;	 Catch:{ IOException -> 0x00c7 }
    L_0x01a2:
        throw r0;	 Catch:{ IOException -> 0x00c7 }
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.exoplayer2.upstream.AssetDataSource.ˋ(com.google.android.exoplayer2.upstream.DataSpec):long");
    }

    public int ˋ(byte[] bArr, int i, int i2) throws AssetDataSourceException {
        if (i2 == 0) {
            return 0;
        }
        if (this.ॱ == 0) {
            return -1;
        }
        try {
            if (this.ॱ != -1) {
                i2 = (int) Math.min(this.ॱ, (long) i2);
            }
            int read = this.ˏ.read(bArr, i, i2);
            if (read != -1) {
                if (this.ॱ != -1) {
                    this.ॱ -= (long) read;
                }
                ˊ(read);
                return read;
            } else if (this.ॱ == -1) {
                return -1;
            } else {
                throw new AssetDataSourceException(new EOFException());
            }
        } catch (IOException e) {
            throw new AssetDataSourceException(e);
        }
    }

    @Nullable
    public Uri ˊ() {
        return this.ˎ;
    }

    public void ॱ() throws AssetDataSourceException {
        this.ˎ = null;
        try {
            if (this.ˏ != null) {
                this.ˏ.close();
            }
            this.ˏ = null;
            if (this.ˋ) {
                this.ˋ = false;
                ˏ();
            }
        } catch (IOException e) {
            throw new AssetDataSourceException(e);
        } catch (Throwable th) {
            this.ˏ = null;
            if (this.ˋ) {
                this.ˋ = false;
                ˏ();
            }
        }
    }
}
